import React, {Component} from 'react'
export default class History extends Component {
    constructor(){
        super()
        this.state = {
            keyword:''
        }
    }
    handleKeyword(e){
        if(this.props.onSearch){
            this.props.onSearch(e.target.dataset.value)
        }
        if(this.props.handleHistoryKeyword){
            this.props.handleHistoryKeyword(e.target.dataset.value)
        }
    }
    render(){
        const history = this.props.history || []
        return(
            <div className="searchHistory">
                {history.length >0 && 
                    <p>历史搜索纪录</p>}
                {history.map((history,i)=>{
                    return (
                        <span 
                            key={i}
                            data-value={history}
                            onClick={this.handleKeyword.bind(this)}>{history}</span>
                    )
                })}
            </div>
        )
    }
}

History.defaultProps = {
    history: []
}